import { CareerConfig } from "../../../resource/CareerConfig";
import { Cache } from "../../../cache/Cache";
import { ShopItemInfo } from "../../../resource/info/ShopItemInfo";
import { StrengthenAddInfo } from "../../../resource/info/StrengthenAddInfo";
import { ItemData } from "../../../resource/info/ItemData";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { Language } from "../../../../../extend/language/Language";
import { EJewel } from "../../../../../Message/Public/EJewel";
import { EAttackType } from "../../../../../Message/Public/EAttackType";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { ImagesConst } from "../../../resource/ImagesConst";
import { BaseItem } from "../../common/BaseItem";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { TCareer } from "../../../../../Message/Db/Tables/TCareer";
type int = number;
//class ShopMeritItem
    
    export  class ShopMeritItem /* flash.display.Sprite */
    {
        constructor(arg1: Boolean)
        {
            
            this._attrTxtArray = [];
            this._attrAddTxtArray = [];
            this._isAttrMuti = arg1;
            this.init();
            this._tCareer = CareerConfig.instance.getInfoByCode(Cache.instance.role.entityInfo.career);
            this._attackType = this._tCareer.attackType;
            return;
        }

        public update(arg1: ShopItemInfo, arg2: StrengthenAddInfo, arg3: StrengthenAddInfo=null): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=null;
            var loc7=null;
            var loc8=null;
            var loc9=0;
            var loc10=null;
            var loc11=0;
            this._myMedalCode = Cache.instance.role.medalCode;
            if (arg1) 
            {
                loc1 = new ItemData(arg1.itemInfo.item.code);
                this._baseItem.itemData = loc1;
                this._nameTxt.htmlText = ItemsUtil.getItemName(loc1);
                this._minTxt.text = arg1.tshopSell.price.toString();
                if (this._myMedalCode != loc1.itemCode) 
                {
                    if ((loc2 = Cache.instance.role.money.merit) >= arg1.tshopSell.price) 
                    {
                        this._statusTxt.htmlText = Language.getString(53091);
                    }
                    else 
                    {
                        this._statusTxt.htmlText = Language.getString(53092);
                    }
                }
                else 
                {
                    this._statusTxt.htmlText = Language.getString(53090);
                }
            }
            if (arg2) 
            {
                loc7 = arg2.addInfoArray.filter(this.filterByAttackType);
                loc8 = [];
                loc11 = 0;
                while (loc11 < this._attrTxtArray.length) 
                {
                    loc3 = this._attrTxtArray[loc11];
                    loc9 = (loc4 = loc7[loc11] as Map<any, any> /* flash.utils.Dictionary */)["type"] as int;
                    loc10 = loc4["name"] as string;
                    if (loc9 == EJewel._EJewelMagicAttack || loc9 == EJewel._EJewelMagicCrit || loc9 == EJewel._EJewelPhysicalAttack || loc9 == EJewel._EJewelPhysicalCrit) 
                    {
                        loc10 = loc10.substr(2);
                    }
                    loc3.text = loc10 + loc4["value"];
                    if (arg3) 
                    {
                        loc8 = arg3.addInfoArray.filter(this.filterByAttackType);
                        loc5 = this._attrAddTxtArray[loc11];
                        loc6 = loc8[loc11] as Map<any, any> /* flash.utils.Dictionary */;
                        loc5.text = (int(loc4["value"]) - int(loc6["value"])).toString();
                    }
                    ++loc11;
                }
            }
            return;
        }

        /* internal  */filterByAttackType(arg1: Map<any, any> /* flash.utils.Dictionary */, arg2: int, arg3: Array<any>): Boolean
        {
            var loc1=arg1["type"] as int;
            if (this._attackType != EAttackType._EAttackTypePhysical) 
            {
                if (!(loc1 == EJewel._EJewelPhysicalAttack) && !(loc1 == EJewel._EJewelPhysicalCrit)) 
                {
                    return true;
                }
            }
            else if (!(loc1 == EJewel._EJewelMagicAttack) && !(loc1 == EJewel._EJewelMagicCrit)) 
            {
                return true;
            }
            return false;
        }

        /* internal  */init(): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=0;
            this._statusTxt = ObjCreate.createGTextField("", 0, 0, 80, 20, this, GlobalStyle.textFormat6);
            this._statusTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            ObjCreate.createBg(0, 22, 38, 38, this, ImagesConst.PackItemBg);
            this._baseItem = new BaseItem();
            this._baseItem.setSize(32, 32);
            this._baseItem.move(3, 25);
            this.addChild(this._baseItem);
            this._nameTxt = ObjCreate.createGTextField("", 42, 22, 100, 20, this);
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            ObjCreate.createGTextField(Language.getString(53093), 42, 45, 100, 20, this);
            this._minTxt = ObjCreate.createGTextField("", 140, 45, 80, 20, this, GlobalStyle.textFormat6);
            this._minTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            ObjCreate.createGTextField(Language.getString(53094), 0, 65, 150, 20, this, GlobalStyle.textFormat4);
            loc4 = 0;
            while (loc4 < 5) 
            {
                loc1 = ObjCreate.createGTextField("", 0, 0, 150, 20, this, GlobalStyle.textFormatGreen);
                loc1.autoSize = flash.text.TextFieldAutoSize.LEFT;
                if (this._isAttrMuti) 
                {
                    if (loc4 < 3) 
                    {
                        loc1.x = 0;
                        loc1.y = 85 + loc4 * 22;
                    }
                    else 
                    {
                        loc1.x = 100;
                        loc1.y = 85 + (loc4 - 3) * 22;
                    }
                }
                else 
                {
                    loc1.x = 0;
                    loc1.y = 85 + loc4 * 18;
                    loc3 = ObjCreate.createBitmap(ImagesConst.RangeRaise, 110, 85 + loc4 * 18, this);
                    loc2 = ObjCreate.createGTextField("", 125, 85 + loc4 * 18, 150, 20, this, GlobalStyle.textFormatGreen);
                    loc2.autoSize = flash.text.TextFieldAutoSize.LEFT;
                }
                this._attrTxtArray.push(loc1);
                this._attrAddTxtArray.push(loc2);
                ++loc4;
            }
            return;
        }

        /* internal */ /* var */_statusTxt: GTextFiled;

        /* internal */ /* var */_nameTxt: GTextFiled;

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_minTxt: GTextFiled;

        /* internal */ /* var */_isAttrMuti: Boolean;

        /* internal */ /* var */_attrTxtArray: Array<any>;

        /* internal */ /* var */_attrAddTxtArray: Array<any>;

        /* internal */ /* var */_myMedalCode: int;

        /* internal */ /* var */_tCareer: TCareer;

        /* internal */ /* var */_attackType: int;
    }
